package com.niodata.dp.core.usermgr.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonView;
import com.niodata.dp.core.usermgr.view.AdminGroupsView;
import com.niodata.dp.core.usermgr.view.AdminUsersView;
import com.niodata.dp.core.usermgr.view.GroupListView;
import com.niodata.dp.core.usermgr.view.GroupMasterView;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

@JsonInclude(Include.NON_NULL)
public class GroupInfo implements Serializable {

  private Long groupId;
  private String groupName;
  private boolean active;
  private String detail;
  // 文件Home目录
  private String hdfsHome;
  // 组内置的拥有者 username
  private String hdfsUser;
  // 只读用户
  private String readerUser;

  private String hdfsGroupName;

  private Timestamp createTime;

  private List<GroupProfile> profiles;

  private boolean sync;

  public static GroupProfile getProfile(List<GroupProfile> profiles, String type) {
    if (profiles != null) {
      for (GroupProfile p : profiles) {
        if (p.getType().equals(type)) {
          return p;
        }
      }
    }
    return null;
  }

  public List<GroupProfile> getProfiles() {
    return profiles;
  }

  public void setProfiles(List<GroupProfile> profiles) {
    this.profiles = profiles;
  }

  @JsonView(value = {AdminGroupsView.class, GroupMasterView.class, GroupListView.class})
  public Long getGroupId() {
    return groupId;
  }

  public void setGroupId(Long groupId) {
    this.groupId = groupId;
  }

  @JsonView(value = {AdminUsersView.class, AdminGroupsView.class, GroupMasterView.class,
        GroupListView.class})
  public String getGroupName() {
    return groupName;
  }

  public void setGroupName(String groupName) {
    this.groupName = groupName;
  }

  @JsonView(value = {AdminGroupsView.class, GroupMasterView.class})
  public String getDetail() {
    return detail;
  }

  public void setDetail(String detail) {
    this.detail = detail;
  }

  @JsonView(value = {AdminGroupsView.class})
  public String getHdfsHome() {
    return this.hdfsHome;
  }

  public void setHdfsHome(String hdfsDirectory) {
    this.hdfsHome = hdfsDirectory;
  }

  public String getHdfsUser() {
    return hdfsUser;
  }

  public void setHdfsUser(String hdfsUser) {
    this.hdfsUser = hdfsUser;
  }

  public String getReaderUser() {
    return readerUser;
  }

  public void setReaderUser(String readerUser) {
    this.readerUser = readerUser;
  }

  @JsonView(value = {AdminGroupsView.class})
  public boolean isActive() {
    return active;
  }

  public void setActive(boolean active) {
    this.active = active;
  }

  public Timestamp getCreateTime() {
    return createTime;
  }

  public void setCreateTime(Timestamp createTime) {
    this.createTime = createTime;
  }

  public String getHdfsGroupName() {
    return hdfsGroupName;
  }

  public void setHdfsGroupName(String hdfsGroupName) {
    this.hdfsGroupName = hdfsGroupName;
  }

  public boolean isSync() {
    return sync;
  }

  public void setSync(boolean sync) {
    this.sync = sync;
  }
}
